﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TpSettings;
using GUI.Controllers;

namespace GUI.Base
{
	public partial class BaseForm : Form
	{
		
		#region Members

		

		#endregion

		#region Construction

		public BaseForm()
		{
			InitializeComponent();
		}

		#endregion

		#region Properties

		protected bool IsDirty
		{
			get;
			set;
		}

		public bool IsNew
		{
			get;
			set;
		}

		#endregion

		#region Methods

		protected void SetFormDirty(object sender, EventArgs e)
		{
			Control ctl = sender as Control;
			
			if (!IsDirty)
			{
				IsDirty = true;
			}
		}

		protected DialogResult DataHasChangedMessage(string messageTitle)
		{
			return MessageBox.Show(TpResource.FormDataHasChangedQuestion, messageTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
		}

		public virtual void SaveFormToModel() {}

		protected void FormClosingEvent(object sender, FormClosingEventArgs e, BaseTpController controller)
		{
			if (IsDirty)
			{
				DialogResult rs = DataHasChangedMessage(this.Text);
				if (rs == DialogResult.Yes)
				{
					SaveFormToModel();
					controller.Save();
				}
				if (rs == DialogResult.Cancel)
				{
					e.Cancel = true;

				}
			}
		}

		#endregion

	}
}
